/**
 * 
 */
package com.shark.app.common.utils;

import java.util.Locale;

import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;
import org.springframework.context.support.MessageSourceAccessor;

import com.shark.app.bean.MessageInfo;

/**
 * @author lenovo
 * @description
 * @date 2016年8月16日
 */
public class MessageUtil implements MessageSourceAware {

	private static MessageSourceAccessor messageSourceAccessor;

	@Override
	public void setMessageSource(MessageSource messageSource) {
		messageSourceAccessor = new MessageSourceAccessor(messageSource, Locale.CHINA);
	}

	public static String getLocaleMessage(String code) {
		return getLocaleMessage(code, new Object[] {});
	}

	public static String getLocaleMessage(String code, Object... args) {
		return messageSourceAccessor.getMessage(code, args, "");
	}

	public static MessageInfo getLocaleMessageInfo(String code) {
		return getLocaleMessageInfo(code, new Object[] {});
	}

	public static MessageInfo getLocaleMessageInfo(String code, Object... args) {
		return new MessageInfo(code, getLocaleMessage(code, args));
	}

}
